import React from 'react';
import { format } from '@/utils/datetime';
import { renderNumber } from '@/utils/common';
import CommonPage from '@/components/page/CommonPage';
const daoName = 'CompLsdk';
const importName = 'CompLsdk';
const options = [
  { value: '1', label: '清洁能源' },
  { value: '2', label: '清洁生产' },
  { value: '3', label: '生态环境' },
  { value: '4', label: '绿色建筑' },
  { value: '5', label: '其他' },
];
const columns: API.Column[] = [
  {
    title: '导入日期',
    width: 120,
    sorter: true,
    key: 'DTID',
    dataIndex: 'DTID',
    render: (data) => format(data, 'yyyy-MM-dd'),
    dispaly: true,
    filter: true,
    export: false,
  },
  {
    title: '借据或票据编号',
    width: 220,
    sorter: true,
    dataIndex: 'EVNO',
    key: 'EVNO',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '组织机构代码',
    width: 160,
    sorter: true,
    dataIndex: 'JGDM',
    key: 'JGDM',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '客户名称',
    width: 200,
    sorter: true,
    dataIndex: 'CUNM',
    key: 'CUNM',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '指导目录',
    width: 180,
    sorter: true,
    dataIndex: 'ZDML',
    key: 'ZDML',
    render: (id) => {
      const item = options.find((i) => i.value === id);
      if (item) {
        return item.label;
      }
      return '';
    },
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '绿色贷款余额(万元)',
    width: 200,
    className: 'column-money',
    sorter: true,
    dataIndex: 'LSBL',
    render: (data) => renderNumber('.2f', data),
    key: 'LSBL',
    align: 'right',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '绿色贷款占比',
    width: 160,
    className: 'column-money',
    sorter: true,
    dataIndex: 'LSZB',
    render: (data) => renderNumber('.2f%', data),
    key: 'LSZB',
    align: 'right',
    dispaly: true,
    filter: true,
    export: true,
  },
];

const controls: API.Control[] = [
  {
    name: 'DTID',
    rules: [{ required: true, message: '不能为空' }],
    type: 'date',
    dataType: 'date',
    label: '导入日期',
    grid: 12 / 24,
  },
  {
    name: 'EVNO',
    rules: [{ required: true, message: '不能为空' }],
    type: 'text',
    label: '借据编号',
    grid: 12 / 24,
  },
  {
    name: 'JGDM',
    rules: [{ required: true, message: '不能为空' }],
    type: 'text',
    label: '机构代码',
    grid: 12 / 24,
  },
  {
    name: 'CUNM',
    rules: [{ required: true, message: '不能为空' }],
    type: 'text',
    label: '客户名称',
    grid: 12 / 24,
  },
  {
    name: 'ZDML',
    label: '指导目录',
    type: 'select',
    grid: 12 / 24,
    dataType: 'string',
    options: options,
    rules: [{ required: true, message: '指导目录不能为空' }],
  },
  {
    name: 'LSBL',
    label: '绿色贷款余额',
    rules: [{ required: true, message: '绿色贷款余额不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
  {
    name: 'LSZB',
    label: '绿色贷款占比',
    rules: [{ required: true, message: '绿色占比不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
];

const CompLsdkForm: React.FC = () => {
  return (
    <CommonPage
      daoName={daoName}
      columns={columns}
      controls={controls}
      title="绿色贷款"
      importName={importName}
      importControls={controls}
      importMode="DeleteAfterInsert"
      importParamNames={['DTID']}
      importTemplateName="绿色贷款导入"
      initSorter={{ FieldName: 'DTID', Direction: 'DESC' }}
    />
  );
};

export default CompLsdkForm;
